<?php
declare(strict_types=1);

namespace app\shop\service;

use app\shop\library\ShopAuth;
use app\shop\model\user\UserAddressModel;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;

class UserAddressService
{
    /**
     * 获取所有地址
     * @return array
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public static function getAllAddress(): array
    {
        return UserAddressModel::where(['user_id' => ShopAuth::instance()->id])
            ->field(['id', 'name', 'phone', 'province', 'city', 'county', 'address', 'is_default', 'full_location'])
            ->order(['is_default' => 'desc'])
            ->select()
            ->toArray();
    }
}